import java.util.LinkedList;
import java.util.Queue;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
class Solution {
    boolean[][] visited;
    int[] dx = {0, 0, 1, -1};
    int[] dy = {1, -1, 0, 0};
    public int[][] highestPeak(int[][] isWater) {
        int m = isWater.length;
        int n = isWater[0].length;
        Queue<int[]> queue = new LinkedList<>();
        //返回结果
        int[][] ret;
        //初始化visited
        visited = new boolean[m][n];

        for(int i = 0; i < m; i++)
            for(int j = 0; j < n; j++)
                if(isWater[i][j] == 1){
                    queue.offer(new int[]{i, j});
                    isWater[i][j] = 0;
                    visited[i][j] = true;
                }

        while(!queue.isEmpty()){
            int[] poll =  queue.poll();
            int height = isWater[poll[0]][poll[1]];//记录当前陆地的高度
            for(int k = 0; k < 4; k++){
                int x = dx[k] + poll[0];
                int y = dy[k] + poll[1];
                if(x >= 0 && x < m && y >= 0 && y < n
                        && isWater[x][y] == 0 && !visited[x][y]){
                    isWater[x][y] = height + 1;
                    visited[x][y] = true;
                    queue.offer(new int[]{x, y});
                }
            }
        }
        return ret = isWater;
    }
}